package com.gxg.dao;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

@Repository
public class NodeCountDao
{
  @Autowired
  private JdbcTemplate jdbcTemplate;
  
  public int getCount()
  {
    String sql = "select count(*) from NodeCount";
    int rowCount = ((Integer)this.jdbcTemplate.queryForObject(sql, Integer.class)).intValue();
    return rowCount;
  }
  
  public void addNodeCount(int id, int count)
  {
    String sql = "insert into NodeCount values(?, ?)";
    this.jdbcTemplate.update(sql, new Object[] { Integer.valueOf(id), Integer.valueOf(count) });
  }
  
  public int getNodeCount()
  {
    String sql = "select count from NodeCount where id=1";
    int count = ((Integer)this.jdbcTemplate.queryForObject(sql, Integer.class)).intValue();
    return count;
  }
  
  public void updateNodeCount(int nodeCount)
  {
    String sql = "update NodeCount set count=? where id=1";
    this.jdbcTemplate.update(sql, new Object[] { Integer.valueOf(nodeCount) });
  }
}
